package webTest.charset;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by IFT8 on 2015/1/19.
 */
public class CharsetDemo extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		response.setHeader("Content-Type", "text/html;charset=utf-8");
//		response.getOutputStream().write("中国".getBytes("utf-8"));

        //response.setCharacterEncoding("utf-8");//指定服务器将输出的字符转为二进制时使用哪张码表
        //response.setHeader("Content-Type", "text/html;charset=utf-8");//设置头通知浏览器用utf-8打开

       // response.setCharacterEncoding("utf-8"); 当使用setContentType时自动按其编码进行转换
        response.setContentType("text/html;charset=utf-8");//一行代码解决输出数据的乱码问题
        response.getWriter().write("中国");
    }
}
